class Solution {
public:
    int sumOfLeftLeaves(TreeNode* root) {
        if (!root) return 0;
        int result = 0;
        queue<TreeNode *> q;
        q.push(root);
        while (!q.empty()) {
            TreeNode *node = q.front();
            q.pop();
            if (node->left && !node->left->left && !node->left->right) {
                result += node->left->val;
            }
            if (node->left) q.push(node->left);
            if (node->right) q.push(node->right);
        }
        return result;
    }
};

class Solution1 {
public:
    int sumOfLeftLeaves(TreeNode* root) {
        if (!root) return 0;
        int result = 0;
        if (root->left) {
            if (!root->left->left && !root->left->right)
                result += root->left->val;
            else
                result += sumOfLeftLeaves(root->left);
        }
        if (root->right) {
            if (root->right->left || root->right->right)
                result += sumOfLeftLeaves(root->right);
        }
        return result;
    }
};
